#pragma once

#include "file_helper.h"

file_helper::~file_helper()
{
    close();
}

void file_helper::open(const filename_t &filename)
{
    close();
    if (!os::fopen(m_fd, filename, "r"))
    {
        perror("打开文件失败");
        return;
    }
    m_filename = filename;
}

void file_helper::close()
{
    if (m_fd != nullptr)
    {
        os::fclose(m_fd);
        m_fd = nullptr;
    }
}

void file_helper::write(const std::string &buffer)
{
    os::fwrite(m_fd, buffer.data(), buffer.size());
}

void file_helper::flush()
{
    os::fflush(m_fd);
}